<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONArray"%>
<%@page import="java.sql.Connection"%>
<%@page import="utils.DBConnection"%>
<%@page import="utils.Getter"%>
<%@page import="java.io.BufferedReader"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	response.setCharacterEncoding("UTF-8");
	request.setCharacterEncoding("UTF-8");
	response.setHeader("Cache-Control", "no-cache"); // HTTP 1.1
	response.setHeader("Pragma", "no-cache"); // HTTP 1.0
	response.setDateHeader("Expires", 0);// Prevents caching at the proxy server
	response.setContentType("text/html;charset=UTF-8");
	response.setHeader("Access-Control-Allow-Origin", "*");

	StringBuffer str = new StringBuffer();
	String line = null;
	try {
		BufferedReader reader = request.getReader();
		while ((line = reader.readLine()) != null)
			str.append(line);
	} catch (Exception e) {
		System.out.println(e);
	}
	Getter getter = new Getter();
	System.out.println(str.toString());
	Connection conn = new DBConnection().getConnection();
	int pageId = getter.getPageId(str.toString(), conn);
	System.out.println(str.toString() + "'s id is " + pageId);
	JSONArray markers = getter.getMarkers(request.getRemoteAddr(),
			pageId, conn);
	JSONObject comments = getter.getComments(request.getRemoteAddr(),
			pageId, conn);
	conn.close();
	String s = "{\"pageId\":" + pageId + ",\"data\":"
			+ markers.toString() + ",\"cmnts\":" + comments.toString()
			+ "}";
	System.out.println(s);
	out.write(s);
%>